Design Notes for PIC10F206 Light Dimmer Firmware

Features and Functions
1.	Based on power interrupts, light is cycled through
	3 preset intensity levels.
2.	Uses AC zero cross to time system for 4 hour auto
	shutdown.
3.	Uses IR remote for manual control of dimming.
4.	Uses sleep mode to minimize current draw.

Use the Watch Dog Timer as a Wakeup from sleep such that if x number of
zero cross detects do not occur, then it must be a intensity change.
If y number of zero cross detects do not occur, then it is a power down.

Algorithm

#define	phase	zero cross raw input
#define PWM	triac drive output

done_flag      = false
mode           = 8
IR_min         = 15
IR_counter     = 16
loop
{
	if (zero_cross)
	{
		IR_receiver = on
		counter     = 0
		done_flag   = false
		dead_count  = 25
		if (phase)
		{
			if (!msb(count1))
			{
				delay(count1)
				pulse PWM
			}
		}
		else
		{
			if (!msb(count2))
			{
				delay(count2)
				pulse PWM
			}
		}
		if ((IR_data == 0) and (IR_counter > 0))
		{
			IR_counter--
			IR_min       = IR_counter
			dark_counter = 0
		}
		if (IR_data == 1)
		{
			IR_counter   = 16
			if (dark_counter < 31) dark_counter++
			if (dark_counter = 31)
			{
				dark_counter = 255
				if ((IR_min < 13) and (IR_min > 7))
				{
					if (--mode == -1) mode = 8
				}
				if ((IR_min < 8) and (IR_min > 0))
				{
					if (++mode == 9) mode = 0
				}
				IR_min = 16
			}
		}
	}
	if (WDT) or (POR)
	{
		if (WDT timeout)
		{
			turn off IR receiver
			if (--dead_count == 0) mode = 0
		}
		if (done_flag == false)
		{
			if (--mode == 0) mode = 8
			done_flag = true
		}
		reset WDT
	}
	count1 = table1[mode]
	count2 = table2[mode]
	sleep
}


PWM algorithm

Table of timer values for 8 intensities and off
Positive Half
0	off		; all off
1	822		; 12.5% on
2	56C		; 25.0% on
3	2B6		; 37.5% on
4	000		; 50.0% on
Negative Half
0	off		; 50.0% on
1	822		; 62.5% on
2	56C		; 75.0% on
3	2B6		; 87.5% on
4	000		;100.0% on

At zero cross, check for delay 1 and 2.  Alternate 1 and then 2
with each zero cross.

	Delay1		Delay2		Intensity
-----------------------------------------------------
0	8000		8000		  0.0%
1	0822		8000		 12.5%
2	056C		8000		 25.0%
3	02B6		8000		 37.5%
4	0000		8000		 50.0%
5	0000		0822		 62.5%
6	0000		056C		 75.0%
7	0000		02B6		 87.5%
8	0000		0000		100.0%
